package git.determinal.template.view;




import java.util.Arrays;

public enum FieldType {
    STRING("string", "字符串"),
    INT("int", "整形"),
    FLOAT("float", "浮点数"),
    DOUBLE("double", "长整形"),
    DATE("date", "日期类型"),
    DATE_TIME("datetime", "日期时间类型"),
    TIME("time", "时间类型");

    private String value;
    private String label;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLabel() {
        return this.label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    private FieldType(String value, String label) {
        this.value = value;
        this.label = label;
    }

    public boolean equal(FieldType fieldType) {
        return this.value.toUpperCase().equals(fieldType.getValue().toUpperCase());
    }

    public static FieldType getType(Class clazz, String fieldName) {
        FieldType type = STRING;

        try {
            Class fieldClazz = ClassUtil.getFieldClass(clazz, fieldName);
            if (fieldClazz == null) {
                return type;
            }

            if ("java.lang.String".equals(fieldClazz.getName())) {
                type = STRING;
            }

            if ("java.lang.Integer".equals(fieldClazz.getName())) {
                type = INT;
            }

            if ("java.lang.Float".equals(fieldClazz.getName())) {
                type = FLOAT;
            }

            if ("java.lang.Double".equals(fieldClazz.getName())) {
                type = DOUBLE;
            }

            if ("java.sql.Timestamp".equals(fieldClazz.getName())) {
                type = DATE_TIME;
            }

            if ("java.sql.Date".equals(fieldClazz.getName())) {
                type = DATE;
            }

            if ("java.sql.Time".equals(fieldClazz.getName())) {
                type = TIME;
            }
        } catch (Exception var4) {
            var4.printStackTrace();
        }

        return type;
    }

    public static FieldType load(String value) {
        return value != null && !"".equals(value) ? (FieldType)Arrays.stream(values()).filter((enumObj) -> {
            return enumObj.getValue().toUpperCase().equals(value.toUpperCase());
        }).findFirst().get() : STRING;
    }
}




